package com.iplay.实战java高并发程序设计.chapter5.c58;

import java.util.Arrays;

/**
 * @author dangwu
 * @since 2021/11/9 2:20 下午
 */
public class BubbleSort {
    public static void main(String[] args) {
        int[] arr = {1,9,5,3,6,2};
        bubbleSort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void bubbleSort(int[] arr){
        if (arr == null) return;
        for (int i = arr.length-1; i > 0 ; i--) {
            for (int j = 0; j < i; j++) {
                if (arr[j] > arr[j+1]){
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] =temp;
                }
            }
        }
    }
}
